<?php

namespace App\Http\Service;

use App\Libs\HttpCurlLibrary;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use App\Models\Productcategory;
//app 首页产品分类
class ProductcategoryService extends BaseService
{
   
    public function __construct(Productcategory $model)
    {
        parent::__construct();
        $this->model=$model;
    }

    public  function getList($request,$data=[])
    {
        $limit=$data['limit'];
        $where=[
            'parent_id'=>'0',
            'status'=>'1',
        ];
        $fileds=['id','name','parent_id','level','image_url'];
        if($limit){
            $list=$this->model->select($fileds)->where($where)->limit($limit)->orderBy('sort', 'asc')->get()->toArray();
        }else{
            #$this->getLastSql();
            $list=$this->model->select($fileds)->where($where)->orderBy('sort', 'asc')->get()->toArray();
        }
        
        return $list;
    }

    public  function getList2($request,$data=[])
    {
        $limit=$data['limit'];
        $fileds=['id','name','parent_id','level','image_url'];
        $where=[
            'status'=>'1',
            'parent_id'=>$data['category_id']
        ];
        if($limit){
            $list=$this->model->where($where)->select($fileds)->limit($limit)->orderBy('sort', 'asc')->get()->toArray();
        }else{
            $list=$this->model->where($where)->select($fileds)->orderBy('sort', 'asc')->get()->toArray();
        }
        
        return $list;
    }
    

}
